package com.example.test;

import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component.Event;

public class ActualizarEstadoReserva {
	
	private OptionGroup tipoReserva = new OptionGroup("Tipo de Rerserva");
	private Table reservasInd = new Table("Reservas Independientes");
	private Table reservasFijas = new Table("Reservas Fijas");
	private Button btnSalir = new Button("Salir");
	private Label lblAlta = new Label("Actualizar estado de las Reservas");
	Panel panel = new Panel();
	Panel panelR = new Panel();
	VerticalLayout vl = new VerticalLayout();
	
	public Panel panelActualizarEstadoReserva(){
		
		
		tipoReserva.addItem("Independientes");
		tipoReserva.addItem("Fijas");
		tipoReserva.addStyleName("vertical");
		tipoReserva.setSizeUndefined();
		tipoReserva.setImmediate(true);
		
		
		
		
				
		
		
		vl.setMargin(true);
		vl.setStyleName("vLayout");
		vl.addComponent(tipoReserva);
		
		
		tipoReserva.addValueChangeListener(new ValueChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void valueChange(ValueChangeEvent event) {
				if(event.getProperty().getValue().equals("Independientes"))
					panelIndependientes();
				else if(event.getProperty().getValue().equals("Fijas"))
					panelFijas();
				
			}
		});
		//vl.addComponent(panelR);
		panel.setContent(vl);
		return panel;
		
		
		
	}
	
	private void panelIndependientes(){
		
		reservasInd.addContainerProperty("Reserva", String.class,null);
		reservasInd.addContainerProperty("Numero", Integer.class,null);
		reservasInd.addItem(new Object[]{"reservaI1", 1},1);
		reservasInd.addItem(new Object[]{"reservaI2",2},2);
		reservasInd.setPageLength(3);
		
		reservasInd.setSelectable(true);
		reservasInd.setImmediate(true);
		vl.removeAllComponents();
		vl.addComponent(tipoReserva);
		vl.setMargin(true);
		vl.setStyleName("vLayout");
		VerticalLayout vLayout = new VerticalLayout();
		vLayout.setStyleName("vLayout");
		HorizontalLayout hLayout = new HorizontalLayout();
		vLayout.addComponent(new Label("&nbsp;", ContentMode.HTML));
		vLayout.addComponent(reservasInd);
		vLayout.setComponentAlignment(reservasInd, Alignment.MIDDLE_CENTER);
		hLayout.setSpacing(true);
		hLayout.addComponent(btnSalir);
		lblAlta.setSizeUndefined();
		vl.addComponent(lblAlta);
		vl.addComponent(vLayout);
		vl.addComponent(new Label("&nbsp;", ContentMode.HTML));
		vl.addComponent(hLayout);
		vl.setComponentAlignment(lblAlta, Alignment.TOP_CENTER);
		vl.setComponentAlignment(vLayout, Alignment.MIDDLE_CENTER);
		vl.setComponentAlignment(hLayout, Alignment.BOTTOM_CENTER);
		

		panel.setContent(vl);
		
		btnSalir.addClickListener(new ClickListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void buttonClick(ClickEvent event) {
				((PaginaPrincipal) UI.getCurrent()).cancelar();
				
			}
		});
		//return panelI;
		
	}
	
	private void panelFijas(){
		
		reservasFijas.addContainerProperty("Reserva", String.class,null);
		reservasFijas.addContainerProperty("Numero", Integer.class,null);
		reservasFijas.addItem(new Object[]{"reservaF1", 1},1);
		reservasFijas.addItem(new Object[]{"reservaF2",2},2);
		reservasFijas.setPageLength(3);
		reservasFijas.setSizeUndefined();
		reservasFijas.setSelectable(true);
		reservasFijas.setImmediate(true);
		vl.removeAllComponents();
		vl.addComponent(tipoReserva);
		vl.setMargin(true);
		vl.setStyleName("vLayout");
		VerticalLayout vLayout = new VerticalLayout();
		vLayout.setStyleName("vLayout");
		HorizontalLayout hLayout = new HorizontalLayout();
		vLayout.addComponent(new Label("&nbsp;", ContentMode.HTML));
		vLayout.addComponent(reservasFijas);
		vLayout.setComponentAlignment(reservasFijas, Alignment.MIDDLE_CENTER);
		hLayout.setSpacing(true);
		hLayout.addComponent(btnSalir);
		lblAlta.setSizeUndefined();
		vl.addComponent(lblAlta);
		vl.addComponent(vLayout);
		vl.addComponent(new Label("&nbsp;", ContentMode.HTML));
		vl.addComponent(hLayout);
		vl.setComponentAlignment(lblAlta, Alignment.TOP_CENTER);
		vl.setComponentAlignment(vLayout, Alignment.MIDDLE_CENTER);
		vl.setComponentAlignment(hLayout, Alignment.BOTTOM_CENTER);
		

		panel.setContent(vl);
		
		btnSalir.addClickListener(new ClickListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void buttonClick(ClickEvent event) {
				((PaginaPrincipal) UI.getCurrent()).cancelar();
				
			}
		});
		
		//return panelF;
	}
	
	

}
